%% Q2 counts vs I
% |10>/|11> + |0,0,-4,1/2
colors = {'#0072BD','#D95319','#7E2F8E','#77AC30'};
colors ={'#00319d','#8887ff','#39ad1f','#cdf4ba','#4aa9eb','#a7d2ef'};

pinks = {'#860454','#c51b7c','#dc75ab','#f0b7da','#FF00FF','#ff81c0'};
greens = {'#276418','#4d921e','#7fbc42','#b9e084','#15b01a','#77AC30'};
purples = {'#410149','#762a84','#9b6fac','#c1a5cd','#800080','#7e1e9c'};
browns = {'#523107','#7f3c0a','#bf812c','#e2c17e','#a0522d','#A2142F'};
pools = {'#003d2e','#01665e','#379692','#81cdc1','#13eac9','#04d8b2'};
reds = {'#68011d','#b5172f','#d75f4e','#f7a580','#ff0000','#e50000'};
blues = {'#062e61','#2265ad','#4295c1','#93c5dc','#40e0d0','#00FFFF'};



X = [0:2:24]; 
% 22+ 0,0,-4,1/2, '20230622_100VR_30G_10kHz_SR_scan_2'
Q2_counts = [43.3750   33.8824   30.5294   27.5625   24.7059   25.3529   21.0000   20.0588   17.2941   19.2941   17.1765   19.0000   18.8667];
Q2_counts_err = [1.6536    1.4264    1.3580    1.3332    1.2226    1.2381    1.1659    1.1083    1.0357    1.0878    1.0323    1.1215    1.1450];



HODT_intensity = 5.55/0.119/1.3*0.119*0.125/0.115 .*(X+1); %kW/cm^2
VODT_intensity = 2.1858 .*(0.6 + X.*0.1) ./ 0.4; % kW/cm^2
ODT_intensity = HODT_intensity + VODT_intensity;




figure(95)
clf
hold on
errorbar(ODT_intensity,Q2_counts,Q2_counts_err,'s','linewidth',2,'markersize',10,'displayname','|22\rangle + |0,0,-4,1/2\rangle','color',hex2RGB(reds{1}),'markeredgecolor',hex2RGB(reds{1}),'markerfacecolor',hex2RGB(reds{4}))
% errorbar(B_list_10,rate_10,e_rate_10,'-o','linewidth',2,'markersize',10,'displayname','|10\rangle + |0,0,-4,1/2\rangle','color',hex2RGB(blues{1}),'markeredgecolor',hex2RGB(blues{1}),'markerfacecolor',hex2RGB(blues{4}))
%errorbar(B_list_11_m3_m05,tau_list_11_m3_m05,tau_err_list_11_m3_m05,'-o','linewidth',2,'markersize',10,'displayname','|11\rangle + |0,0,-3,1/2\rangle','color',hex2RGB(greens{1}),'markeredgecolor',hex2RGB(greens{1}),'markerfacecolor',hex2RGB(greens{4}))

[fitresult, gof] = createFit(ODT_intensity,Q2_counts);
xft = linspace(0,max(ODT_intensity),100);
fit_val = fitresult(xft);
%errorbar(B_list_11_s,tau_11_s,e_tau_11_s,'d','linewidth',2,'markersize',10,'displayname','|11\rangle + |0,0,-4,-3/2\rangle','color','k','markeredgecolor','k','markerfacecolor',hex2RGB('#808080'))

box on; %grid on
% legend
xlabel('ODT intensity (kW/cm^2)')
ylabel('KRb ion counts')
% set(gca,'fontsize',16,'linewidth',2)
set(gca,'fontsize',16)
set(gcf,'color','white')
% xlim([0 140])
% ylim([15 48])
fitresult
plot(xft, fit_val,'-','Linewidth',2,'color',hex2RGB(reds{1}))


function color = hex2RGB(hex)
    color = sscanf(hex(2:end),'%2x%2x%2x',[1 3])/255;
end

function [fitresult, gof] = createFit(ODT_intensity, Q2_counts)
%CREATEFIT(ODT_INTENSITY,Q2_COUNTS)
%  Create a fit.
%
%  Data for 'untitled fit 1' fit:
%      X Input : ODT_intensity
%      Y Output: Q2_counts
%  Output:
%      fitresult : a fit object representing the fit.
%      gof : structure with goodness-of fit info.
%
%  See also FIT, CFIT, SFIT.

%  Auto-generated by MATLAB on 21-Jun-2023 13:31:29


%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( ODT_intensity, Q2_counts );

% Set up fittype and options.
ft = fittype( 'a/(1+b*x+4.2*b*x^2)+17', 'independent', 'x', 'dependent', 'y' );

opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0 ];
opts.StartPoint = [100 0.173119349446203 ];
opts.Upper = [Inf Inf ];


% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );

% Plot fit with data.
% h = plot( fitresult, xData, yData);
% legend( h, 'Q2_counts vs. ODT_intensity', 'Location', 'NorthEast' );
% Label axes
xlabel ODT_intensity
ylabel Q2_counts
% grid on
end

